#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
string s;
int main()
{
    IOS;
    while(cin>>s){
        ll len=s.length();
        ll id=0;
        for(;id<len;id++){
            if(s[id]=='B')break;
        }
        ll ans1=0,ans2=0;
        for(ll i=id-1;i>=0;i--){
            if(s[i]!='(')ans1--;
            else ans1++;
        }
        for(ll i=id+1;i<len;i++){
            if(s[i]!=')')ans2--;
            else ans2++;
        }
        cout<<max(ans1,ans2)<<endl;
    }
    getchar();
    getchar();
    return 0;
}